<?php
require_once('functions/pageLoad.php');
loginRequired();
$user_session = explode("_", $_SESSION['user']);
$user_id = $user_session[0];
$page_title = 'Payment history';

	$sql = "SELECT amount, payment_made, payment_types.payment_type FROM payments 
	LEFT JOIN payment_types ON payments.payment_type = payment_types.id 
	WHERE user_id = '".$user_id."' AND payment_made IS NOT NULL ORDER BY payment_made DESC";
	$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());

	if(mysql_num_rows($query) > 0){

	$content = '<table class="standard" width="100%"><tr><th>Amount</th><th>Type</th><th>Date</th></tr>';

	$i = 2;

	while($rs=mysql_fetch_assoc($query)){

	$highlight = (is_int($i / 2)) ? ' class="highlight"' : '' ;

	$rs['payment_type'] = ($rs['payment_type'] == 'sms') ? 'SMS' : ucfirst($rs['payment_type']) ;

	$content.='<tr'.$highlight.'><td>&pound;'.$rs['amount'].'</td><td>'.$rs['payment_type'].'</td><td>'.date("jS F Y", strtotime($rs['payment_made'])).'</td></tr>';	

	$i++;

	}

	$content.='</table>';

	}

	else{

	$content = '<div class="yellow_box"><p>You have not made any payments to <strong>I Want A Tradesman</strong>.</p></div>';

	}

include('includes/meta.php');
include('includes/header.php');
include('includes/navigation.php');

?>

<h1><?php echo $page_title; ?></h1>

<?php echo $content; ?>

<?php 

include('includes/rightColumn.php');
include('includes/footer.php');

?>